/**
 * 数组转树  递归求解
 */
export function toTree(list,parId){
	let len = list.length
	function loop(parId){
		let res = [];
		for(let i = 0; i < len; i++){
			let item = list[i]
			if(item.id_sj == parId){
				item.children = loop(item.id)
				res.push(item)
			}
		}
		return res
    }
    return new Promise((resolve, reject) =>{
        resolve(loop(parId))
    });
}

export function deepTraversal(data) {
    const result = [];
    data.forEach(item => {
        const loop = data => {
            result.push({
            	id: data.id,
				label: data.mc,
                id_sj: data.id_sj,
                sf_xz: data.selected
            });
            let child = data.children
            if(child){
            	for(let i = 0; i < child.length; i++){
					loop(child[i])
				}
            }
        }
        loop(item);
    })
    return new Promise((resolve, reject) =>{
        resolve(result)
    });
}

export function deepTraversal1(data) {
    const result = [];
    data.forEach(item => {
        const loop = data => {
            result.push({
                id: data.id,
                id_alias:data.id_alias,
                dmmc: data.dmmc,
                children:data.children
            });
            let child = data.children
            if(child){
            	for(let i = 0; i < child.length; i++){
					loop(child[i])
				}
            }
        }
        loop(item);
    })
    return new Promise((resolve, reject) =>{
        resolve(result)
    });
}


 